:- use_module(library(chr)).
:- chr_constraint input/1.
:- chr_constraint preSUM/2.
:- chr_constraint finalSUM/2.

preSUM(X, Y), input(Z) <=> preSUM(A, B), B is Y+1,  A is X+Z.
input(X) <=> preSUM(X, 1), true.
finalSUM(X, Y), preSUM(Z, Y) ==> X=Z, true.